<?php
/**
 * IQ error response
 * 
 * @package stanza.error
 */
abstract class Zend_Jabber_Stanza_Response_Iq_Error extends Zend_Jabber_Stanza_Response_Iq_Abstract {
    // error codes
    const RESULT_CODE_REDIRECT = 302;
    const RESULT_CODE_BAD_REQUEST = 400;
    const RESULT_CODE_UNAUTHORIZED = 401;
    const RESULT_CODE_BAD_PAYMENT_REQUIRED = 402;
    const RESULT_CODE_FORBIDDEN = 403;
    const RESULT_CODE_NOT_FOUND = 404;
    const RESULT_CODE_NOT_ALLOWED = 405;
    const RESULT_CODE_NOT_ACCEPTABLE = 406;
    const RESULT_CODE_REGISTRATION_REQUIRED = 407;
    const RESULT_CODE_REQUEST_TIMEOUT = 408;
    const RESULT_CODE_CONFLICT = 409;
    const RESULT_CODE_INTERNAL_SERVER_ERROR = 500;
    const RESULT_CODE_NOT_IMPLEMENTED = 501;
    const RESULT_CODE_REMOTE_SERVER_ERROR = 502;
    const RESULT_CODE_SERVICE_UNAVAILABLE = 503;
    const RESULT_CODE_REMOTE_SERVER_TIMEOUT = 504;
    const RESULT_CODE_DISCONNECTED = 510;
    
    /**
     * Get response error code
     *
     * @return DomElement
     */
    private function getErrorNode() {
        return $this->dom->firstChild->getElementsByTagName('error')->item(0);
    }
    
    /**
     * Get error type
     *
     * @return string
     */
    public function getErrorType() {
        return $this->getErrorNode()->getAttribute('type');
    }
    
    /**
     * Get error code
     *
     * @return integer
     */
    public function getErrorCode() {
        return $this->getErrorNode()->getAttribute('code');
    }
    
    /**
     * Get error description. 
     * 
     * This is not actual error descrition. This value is guessed from tan names
     *
     * @return string
     */
    public function getErrorMessage() {
        return ucfirst(str_replace('-', ' ', $this->getErrorNode()->firstChild->tagName));
    }
}
?>